home *** CD-ROM | disk | FTP | other *** search
/ The Essential Home & Business Collection / The Essential Home & Business Collection.iso / 27 / 3 / 5 / HP22D5.ZIP / EXTERN / INFO.C < prev    next >
Text File  |  1991-04-16  |  4KB  |  165 lines

  1. #include <dos.h>
  2. #include <stdarg.h>        /* include for variable number of arguments */
  3.  
  4. #include "extern.h"        /* Extensions need these! */
  5.  
  6. extern PTR pascal near Get52Ptr();
  7. extern PTR pascal near emmptr();
  8. extern DWORD pascal near emmfree();
  9. extern DWORD pascal near emmtotal();
  10. extern BYTE pascal near emmversion();
  11. extern WORD pascal near getmemsize();
  12. extern WORD pascal near getextmemsize();
  13. extern WORD pascal near getequipment();
  14.  
  15. PTR pascal near pctype()
  16.  
  17. {
  18.     PTR p = (PTR)0xF000FFFEL;
  19.  
  20.     if (*p == 0xff) return("PC");
  21.     if (*p == 0xfe) return("PC XT");
  22.     if (*p == 0xfd) return("PCjr");
  23.     if (*p == 0xfc) return("PC AT");
  24.     return("Clone");
  25. }
  26.  
  27. static DWORD pascal near blocksize(seg)
  28.  
  29. WORD seg;
  30.  
  31. {
  32.     PTR p;
  33.     FP_SEG(p) = seg;
  34.     FP_OFF(p) = 0;
  35.  
  36.     return(((DWORD)*(WORD *)(p + 3) * 16L));
  37. }
  38.  
  39. static PTR pascal near bool(b)
  40.  
  41. BYTE b;
  42.  
  43. {
  44.     return(b ? "TRUE" : "FALSE");
  45. }
  46.  
  47. /*
  48. ** INFO
  49. **
  50. ** This function returns an item delimited list of information about your
  51. ** computer. The item list is returned as follows:
  52. **
  53. **    item 1    ->    path of HyperPAD
  54. **    item 2    ->    TRUE if DesqView is running, FALSE otherwise
  55. **    item 3    ->    TRUE if a mouse is installed, FALSE otherwise
  56. **    item 4    ->    ps type (PC,PC XT,PCjr,PC AT,Clone)
  57. **    item 5    ->    number of printers
  58. **    item 6    ->    number of RS-232 ports
  59. **    item 7    ->    number of disk drives
  60. **    item 8    ->    TRUE if EMS memory is installed, FALSE otherwise
  61. **    item 9    ->    EMS version number (empty if no EMS installed)
  62. **    item 10    ->    EMS memory free
  63. **    item 11    ->    EMS total number of bytes
  64. **    item 12    ->    free memory available to run programs
  65. **    item 13    ->    total system memory (in bytes)
  66. **    item 14    ->    total extended memory (in bytes)
  67. **    item 15    ->    first allocated DOS memory block (in hex)
  68. **    item 16    ->    next load address (format SEG:OFS)
  69. **    item 17    ->    environment size (in bytes)
  70. **
  71. */
  72. info()
  73.  
  74. {
  75.     HANDLE hdl;
  76.     SHAREDPTR pShared;
  77.     DWORD f,t,free;
  78.     BYTE b,e;
  79.     WORD equip;
  80.     char buf[4];
  81.     WORD FirstSeg,next;
  82.     PTR p,ptr;
  83.  
  84.     pShared = GetSharedArea();
  85.  
  86.     /* allocate the maximum amount of space for the item list text */
  87.     hdl = NewHandle(250);
  88.  
  89.     /* get the EMS information */
  90.         if (b = !strnicmp(emmptr(),"EMMXXXX0",8)) {
  91.         f = emmfree();
  92.         t = emmtotal();
  93.         e = emmversion();
  94.         sprintf(buf,"%c.%c",'0' + (e >> 4),'0' + (e & 0xf));
  95.     }
  96.     else {
  97.         buf[0] = '\0';
  98.         f = t = 0L;
  99.     }
  100.  
  101.     /* get the equipment flags - each bit means something */
  102.     equip = getequipment();
  103.  
  104.     // p = pointer to EXEC memory block
  105.     FP_SEG(p) = FP_SEG(pShared) - 0x11;
  106.     FP_OFF(p) = 0;
  107.  
  108.     // next = segment address of the HPAD.OVL program
  109.     next = FP_SEG(p) += *(WORD *)(p + 3) + 1;
  110.  
  111.     // trace through to end of memory blocks
  112.     do {
  113.         FP_SEG(ptr) = next;
  114.         FP_OFF(ptr) = 0;
  115.  
  116.         if (*ptr == 0x5a) break;
  117.         else if (*ptr != 0x4d) break;    //corrupt();
  118.         next += *(WORD *)(ptr + 3) + 1;
  119.     } while (TRUE);
  120.  
  121.     // free = number of bytes free (not including header)
  122.     free = (DWORD)(next - FP_SEG(p)) * 16L + blocksize(next) + (DWORD)48;
  123.  
  124.     // first allocated DOS segment (interrupt 21, function 52h is undocumented)
  125.     FirstSeg = *(WORD *)(Get52Ptr() - 2);
  126.  
  127.     sprintf(deref(hdl),
  128.         "%s,%s,%s,%s,%d,%d,%d,%s,%s,%lu,%lu,%lu,%lu,%lu,%04X,%04X:0000,%d",
  129.         pShared -> program_name,
  130.         bool(pShared -> flags & 0x20),
  131.         bool(pShared -> flags & 0x04),
  132.         pctype(),
  133.         (equip & 0xC000) >> 14,
  134.         (equip & 0x0e00) >> 9,
  135.         equip & 1 ? ((equip & 0x00C0) >> 6) + 1 : 0,
  136.         bool(b),
  137.         buf,
  138.         f,
  139.         t,
  140.         free,
  141.         (DWORD)getmemsize() * 1000L,
  142.         (DWORD)getextmemsize() * 1000L,
  143.         FirstSeg,
  144.         FP_SEG(p),
  145.         pShared -> EnvSegSz);
  146.  
  147.     // get the exact size of the text
  148.     ReAllocHandle(hdl,strlen(deref(hdl)) + 1);
  149.  
  150.     ReturnValue(hdl);
  151.  
  152.     return(STOP);
  153. }
  154.  
  155. POOL pascal Pool[] = {
  156.     {    "info",            /* name of the handler */
  157.         info,            /* pointer to the handler */
  158.         0,            /* reserved */
  159.         FUNCTION},        /* this is a handler, not a function */
  160.  
  161.     {    NULL,            /* NULLs signify the end of the table */
  162.         NULL,
  163.         0,
  164.         0}    };
  165.